package com.itheima;

import com.itheima.dao.UserDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author: dh
 * @date: 2023-10-22 09:46
 * 运行类.
 */
public class AppForInstanceUser {

    public static void main(String[] args) {

        // 通过工厂实例化对象.
        // UserDaoFactory userDaoFactory = new UserDaoFactory();
        // UserDao userDao = userDaoFactory.getUserDao();

        // 1.获得IoC容器
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 2.通过getBean方法来获得对象.
        UserDao userDao = (UserDao) ctx.getBean("userDao");
        // 调用对象中的方法
        userDao.save();
        // 调用UserDaoFactoryBean中的isSingleton方法，返回false。
        UserDao userDao1 = (UserDao) ctx.getBean("userDao");
        UserDao userDao2 = (UserDao) ctx.getBean("userDao");
        System.out.println(userDao1);
        System.out.println(userDao2);
    }
}
